<?php
/**
 * @file
 * Download Monitor - Allows you to trace file downloads. Just place the direct link
 * to the file on the web, and specify the extensions of files you want to trace in the GUI.
 * It creates interactive chart and records downloads for today, yesterday, this week,
 * last week, this month, last month and total.
 * Requires writable .htaccess file of Apache Web server in Joomla root folder.
 * @package download-monitor
 * @version 1.0
 * @revision @REVISION@
 * @license http://www.gnu.org/licenses/gpl-3.0.txt     GNU General Public License v3
 * @copyright (C) 2012 by CodeGravity.com - All rights reserved!
 * @website http://www.codegravity.com
 */

$db =& JFactory::getDBO();

$currdate = date("Y-m-d");
$preday = date("Y-m-d", (strtotime($currdate)-(6*60*60*24)));

$chartquery = sprintf("select * from #__download_monitor_paths");
$db->setQuery($chartquery);
$chartar = $db->loadRowList();

$fname="";
if (@$chartar)
    foreach($chartar as $cht)
    {
        $fname = $fname."'".$cht[1]."',";

    }
$dailydata="";
for($da=0;$da<7;$da++)
{
    $pday = date("Y-m-d", (strtotime($preday)+($da*60*60*24)));
    $dpday = date("j M Y", strtotime($pday));
    $dailydata.='["'.$dpday.'",';
    if (@$chartar)
        foreach($chartar as $cht1)
        {
            $fid = $cht1[0];
            $filepathquery_tot = sprintf("SELECT COUNT(*) FROM #__download_monitor_counter where did='%d' and ddate='%s'", (int) $fid, mysql_escape_string($pday));
            $db->setQuery($filepathquery_tot);
            $count_tot_dt  = $db->loadResult();

            $dailydata = $dailydata.$count_tot_dt.",";
        }
    $dailydata.='],';
}
echo "['',".$fname."],".$dailydata;
?>